package com.hbnu.collections;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author kittychen
 * @since 2025-10-13 10:54
 */
public class HashMapDemo {
    public static void main(String[] args) {
        Map<String, String> hashMap = new HashMap<>();

        hashMap.put("id", "1");
        hashMap.put("name", "zhangsan");
        hashMap.put("gender", "female");
        hashMap.put("hobby", "eat");

        System.out.println(hashMap.get("name"));   // 根据键获取值

        System.out.println("获取所有key，然后获取对应的value");
        Set<String> keySet = hashMap.keySet();  // 获取所有的key
        for (String key : keySet) {
            String value = hashMap.get(key);  // 根据key获取value
            System.out.println(key + "-->" + value);
        }

        System.out.println("获取所有的value");
        Collection<String> values = hashMap.values();  // 获取所有的value
        for (String value : values) {
            System.out.println(value);
        }
    }
}
